﻿    /// <reference path="../jquery-easyui-1.2.6/jquery-1.7.2.min.js" />
/// <reference path="../jquery-easyui-1.2.6/jquery.easyui.min.js" />
/// <reference path="../json2.js" />
var grd;
var dlgEdit;
var dlgEditForm;

var page = {
    handlePrix: "../handleControl/WarehouseMngr.ashx?func=",

    //初始化页面
    Intail: function () {
        this.LoadAll();
    },

    Modify: function (no) {
        var whsModule = {};
        //        jQuery.post(this.handlePrix + "ModifyWhs", { whs: whsModule, rd: parseInt(Math.random(1) * 10000) }, function () {
        dlgEdit.dialog('open');
        jQuery.get(page.handlePrix + "GetWhsInfoByNo", { no: no, rd: parseInt(Math.random(1) * 10000) }, function (data) {
            var dt = JSON.parse(data);
            jQuery("#whsNoTxt").attr("disabled", true);
            jQuery("#whsNoTxt").val(dt.list["WhsWhs"]);
            jQuery("#whsDescTxt").val(dt.list["WhsDesc"]); ;
        });
    },

    Del: function () {
        var ids = "";
        jQuery.get(this.handlePrix + "DelWhsByID", { id: ids, rd: parseInt(Math.random(1) * 10000) }, function () {

        });
    },

    LoadAll: function () {
        grd = $('#whsListTable').datagrid({
            nowrap: true,
            striped: true,
            remoteSort: false,
            fitColumns: true,
            pageSize: 10,
            url: page.handlePrix + "GetAllWhsInfo&whNo=" + jQuery("#whNo").val(),
            frozenColumns: [[
                    { field: 'ck', checkbox: true }
                ]],
            columns: [[
                    { field: 'WHS_WHS', title: '仓库编号', width: 100 },
                    { field: 'WHS_DESN', title: '仓库描述', width: 100 },
                    { field: 'Operate', title: '操作', width: 70, align: 'center',
                        formatter: function (value, whs, index) {
                            var e = '<a onclick="page.Modify(\'' + whs.WHS_WHS + '\');" title="编辑" iconcls="icon-edit-blue" class="easyui-linkbutton l-btn l-btn-plain" plain="true"><span class="l-btn-left"><span class="l-btn-text"><span class="l-btn-empty icon-edit-blue">&nbsp;</span></span></span></a>';
                            var d = '<a onclick="Delete(\'' + whs.WHS_WHS + '\')" title="删除" iconcls="icon-delete" class="easyui-linkbutton l-btn l-btn-plain" plain="true"><span class="l-btn-left"><span class="l-btn-text"><span class="l-btn-empty icon-delete">&nbsp;</span></span></span></a>';
                            return e + d;
                        }
                    }
                ]],
            // pagination: true,
            rownumbers: true,
            toolbar:
                    [{
                        id: 'btnAdd',
                        text: '添加',
                        iconCls: 'icon-add-blue',
                        handler: Add
                    },
                    '-',
                    {
                        id: 'btnDelete',
                        text: '批量删除',
                        iconCls: 'icon-delete',
                        handler: function () {
                            var rows = $("#whsListTable").datagrid("getSelections");

                            if (rows.length == 0) {
                                $.messager.show({
                                    title: '操作提示',
                                    msg: '请选择您要删除的记录！',
                                    showType: 'slide',
                                    timeout: 3000
                                });
                            }
                            else {
                                $.messager.confirm("操作提示", "您确定要删除选中的记录吗？", function (data) {
                                    if (data) {
                                        var idlist = [];

                                        $.each(rows, function (i, row) {
                                            idlist.push(row.Id);
                                        });

                                        $.ajax({
                                            type: "POST",
                                            url: "User.ashx",
                                            data: "action=delete&ID=" + idlist.join(','),
                                            success: function (data) {
                                                eval('data=' + data);
                                                if (data.success) {
                                                    $.messager.alert('操作提示', '删除成功！', "info", function () {
                                                        $('#whsListTable').datagrid("reload");
                                                    });
                                                }
                                                else {
                                                    $.messager.alert('数据操作异常', data.message, "error");
                                                }
                                            },
                                            error: function () {
                                                $.messager.alert('异步操作异常', '异步操作错误！', "error");
                                            }
                                        });
                                    }
                                });
                            }
                        }
                    }
                ]
        });

        dlgEdit = $("#editWhs").dialog({
            title: '仓库维护',
            closed: true,
            width: 300,
            height: 200,
            closable: true,
            draggable: true,
            resizable: false,
            modal: true,
            buttons:
                [
                    {
                        text: '保存',
                        iconCls: 'icon-ok',
                        handler: Save
                    },
				    {
				        text: '取消',
				        iconCls: 'icon-cancel',
				        handler: function () {
				            dlgEdit.dialog('close');
				        }
				    }
				],
            onClose: function () {
                grd.datagrid('clearSelections');
            };
        });
      
          dlgEditForm = dlgEdit.find('form');

        function Add() {
            dlgEdit.dialog('open');
        };

        function Save() {
            //save
            var whsWhs = jQuery.trim(jQuery("#whsNoTxt").val());
            var whsDesc = jQuery.trim(jQuery("#whsDescTxt").val());

            if (whsWhs == "" || whsDesc == "") {
                $.messager.alert("提示", "必须填入编码与描述信息", "error");
                return;
            }
            //dlgEditForm.url = page.handlePrix + "AddWhs";  //'User.ashx?action=insert';
            //            jQuery.post(page.handlePrix + "AddWhs", { no: whsWhs, desc: whsDesc, rd: parseInt(Math.random(1) * 10000) }, function (data) {
            //                alert(data);
            //            });
        };

        //get del item
    }
};

jQuery(function () { page.Intail(); });